package com.microinvest.controller.user;
import com.microinvest.dao.TransactMapper;
import com.microinvest.entity.Users;
import com.microinvest.service.UserService;
import com.microinvest.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


//此Controller用于用户的注册，修改信息，更新信息
@RestController
@RequestMapping("/user")
public class UserController {

    private final UserService userService;

    @Autowired
    public UserController(UserService userService){
        this.userService=userService;
    }

//    @Autowired
//    private TransactMapper transactMapper;

    //用户注册
    @PostMapping("/register")
    public Result register(String userName,String password,String email) {
        Users user=new Users(userName,password,email);
        //**由前端判断是否为空**
        Result result=userService.registerUserService(user);
        return result;
    }

    //用户修改密码
    @PatchMapping("/updatePwdWithOldPwd")
    public Result<String> updateWithOldPwd(String oldPassword,String newPassword){
        //由前端保存用户临时信息，返回当前用户用户名，输入旧密码以及新密码
        Result result=userService.updateWithOldPwdService(oldPassword,newPassword);
        return result;
    }

    //用户通过邮箱修改密码(忘记密码，第一步发送邮箱)
    @PostMapping("/updatePwdWithEmailStepOne")
    public Result<String> updatePwdWithEmailStepOne(String email){
        Result result=userService.updatePwdWithEmailStepOne(email);
        return result;
    }

    //用户通过邮箱修改密码(忘记密码，第二步验证邮箱验证码)
    @PostMapping("/updatePwdWithEmailStepTwo")
    public Result<String> updatePwdWithEmailStepTwo(String email,String code){
        System.out.println(email+code);
        Result result=userService.updatePwdWithEmailStepTwo(email,code);
        return result;
    }
    //用户通过邮箱修改密码(忘记密码，第三步修改密码)
    @PatchMapping("/updatePwdWithEmailStepThree")
    public Result<String> updatePwdWithEmailStepThree(String newPwd){
        Result result=userService.updatePwdWithEmailStepThree(newPwd);
        return result;
    }
//    @PostMapping("/qwe")
//    public Result stock(int userId,String stockSymbol){
//        int quantity=transactMapper.returnOneStockTotalQuantity(userId,stockSymbol);
//        return Result.success(quantity);
//    }


}
